package org.mobile.model.util;

public class PagebarUtil {

    public static String getPageBar(String url, Long totalCount,
            Long pageCount, Long pageSize, Long pageNo) {
        StringBuffer sb = new StringBuffer();
        if(pageSize == null) {
            pageSize = totalCount / pageCount;
        }
        sb.append("<div class=\"pagination\">");
        sb.append("<ul>");
        sb.append("<li class=\"previous\">");
        sb.append("<a href=\"" + url + "&pageNo=1&pageSize=" + pageSize
                + "\" class=\"\">首页</a>");
        sb.append("</li>");
        int p = (int) (pageNo > 4 ? pageNo - 4 : 1);
        for(int i = p; i < p + 9; i++) {
            if(i <= pageCount) {
                if(i == pageNo)
                    sb.append("<li class=\"active\">");
                else {
                    sb.append("<li>");
                }
                sb.append("<a href=\"" + url + "&pageNo=" + i + "&pageSize="
                        + pageSize + "\">" + (i > 9 ? i : ("0" + i))
                        + "</a></li>");
            }
        }
        sb.append("<li class=\"next\">");
        sb.append("<a href=\"" + url + "&pageNo=" + pageCount + "&pageSize="
                + pageSize + "\" class=\"\">尾页</a>");
        sb.append("</li>");
        sb.append("</ul>");
        sb.append("</div>");
        sb.append("<div class=\"input-div-base\"  style=\"display:inline;margin-left:20px;width:60px\">");
        sb.append("<input onkeyup=\"this.value=this.value.replace(/\\D/g,'')\"  onafterpaste=\"this.value=this.value.replace(/\\D/g,'')\"  id=\"pageNumber\" type=\"text\" class=\"\" value=\""
                + pageNo
                + "\" style=\"display:inline;margin-left:20px;width:60px;height:25px;border-color:#2b8fd1\" />");
        sb.append("</div >");
        sb.append("<label style=\"display:inline;font-size:20px;\" >页/共"
                + pageCount
                + "页</label>"
                + "<button class=\"btn btn-info\" style=\"display:inline;height:30px;line-height:10px\"  onclick=\"goPage()\"> 跳转</button>");
        sb.append("<label id=\"infor\"></label>");
        sb.append("<script language=\"javascript\" type=\"text/javascript\">\r\n");
        sb.append("    function goPage(){\r\n");
        sb.append("        var pageNo = $('#pageNumber').val();\r\n");
        sb.append("        if(pageNo > " + pageCount + "){pageNo=" + pageCount
                + ";}\r\n");
        sb.append("        window.location.href=\"" + url
                + "\"+\"&pageNo=\"+pageNo+" + "\"&pageSize=\"+" + pageSize
                + ";\r\n");
        sb.append("     }\r\n");
        sb.append("</script>\r\n");
        return sb.toString();
    }
}
